#include "Element.h"
#include "SimpleMap.h"
#include "PathFinder.h"
#include "Actions.h"

namespace Core
{
	namespace GameLogic
	{
		Element::Element(Core::Position start,Evironment* e)
			:CommandReceiver(e),now(start)
		{
			//currentAction=stop;
			ParamList* p=new ParamList();
			p->Add("speed",Param(Core::DOUBLE,new double(5)));
			this->AddAction(new Move(this,p));
			this->AddDefaultAction(new Stop());
			//this->AddCommand(new Stop());
		}
		Position  Element::GetPrePosition()const
		{
			return prePosition;
		}
		Position  Element::GetPosition()const
		{
			return now;
		}
		void Element::SetPosition(Position p)
		{

			if(now==p) 
			{
				return;
			}
			//Save position before action. for map to update
			prePosition=now;
			now=p;
			notify(MOVE);
		}
		Element::Dir Element::GetDir() const
		{
			return dir;
		}
		void Element::SetDir(Dir d)
		{
			this->dir=d;
		}
		void Element::AddMove(ActionListener* listener)
		{
			add(listener,MOVE);
		}

		void Element::OnClock(SourceType& clock)
		{
			
			this->Execute();
		}

		Element::~Element()
		{
		}
	}
}